package com.kinghood.authoritycenter.controller.sys;


import com.kinghood.authoritycenter.common.model.dto.sys.DirectionReqExtDTO;
import com.kinghood.authoritycenter.common.model.dto.sys.SystemDirectionReqDTO;
import com.kinghood.authoritycenter.service.ISysDirectionService;
import com.kinghood.infrastructure.api.authority.DirectionRemoteVO;
import com.kinghood.infrastructure.api.authority.DirectionReqRemoteDTO;
import com.kinghood.infrastructure.api.authority.SysLogModuleEnum;
import com.kinghood.infrastructure.aspect.OperatorLog;
import com.kinghood.infrastructure.model.KingHoodException;
import com.kinghood.infrastructure.model.KingHoodResponseVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;
import java.util.Objects;

/**
 * 系统字典
 *
 * @author Mike
 * @version 2019年6月24日上午11:24:50
 */
@RestController
@RequestMapping("/sysDirection")
public class SystemDirectionController {
    @Autowired
    private ISysDirectionService systemDirectionService;

    /**
     * 查询类别列表
     *
     * @param query
     * @return
     * @version 2019年6月20日下午4:50:55
     * @author Mike
     */
    @RequestMapping(value = "/queryDirectionPageList", method = RequestMethod.POST)
    public KingHoodResponseVO<?> queryDirectionPageList(@RequestBody DirectionReqExtDTO query) {
        return KingHoodResponseVO.success(systemDirectionService.queryDirectionPageList(query));
    }

    /**
     * 查询所有规格列表
     *
     * @param query
     * @return
     * @version 2019年6月20日下午4:50:55
     * @author Mike
     */
    @RequestMapping(value = "/queryDirectionBycode", method = RequestMethod.POST)
    public KingHoodResponseVO<?> queryDirectionBycode(@RequestBody DirectionReqExtDTO query) {
        return systemDirectionService.queryDirectionBycode(query);
    }

    /**
     * 新增更新规格
     *
     * @return
     * @version 2019年6月20日下午4:51:30
     * @author Mike
     */
    @OperatorLog(module = SysLogModuleEnum.Type.AUTHORITY_DIRECTION,content = "数据字典管理-新增、修改字典值")
    @RequestMapping(value = "/addOrUpdateDirection", method = RequestMethod.POST)
    public KingHoodResponseVO<?> addOrUpdateDirection(@Valid @RequestBody SystemDirectionReqDTO dirReq) {
        dirReq.genBelongType();
        return systemDirectionService.addorUpdateDirection(dirReq);
    }

    /**
     * 修改规格排序
     *
     * @param param
     * @author jp
     * @date 2024/01/02
     */
    @OperatorLog(module = SysLogModuleEnum.Type.AUTHORITY_DIRECTION,content = "数据字典管理-修改字典值排序")
    @RequestMapping(value = "/updateSort", method = RequestMethod.POST)
    public KingHoodResponseVO<?> updateSort(@RequestBody SystemDirectionReqDTO param) {
        if (Objects.isNull(param.getId())) {
            throw new KingHoodException(-1, "id不能为空");
        }
        if (Objects.isNull(param.getSortNumber())) {
            throw new KingHoodException(-1, "排序不能为空");
        }
        return systemDirectionService.updateSort(param);
    }


    /**
     * 根据ids删除规格
     *
     * @param id
     * @return
     * @version 2019年6月20日下午4:51:46
     * @author Mike
     */
    @OperatorLog(module = SysLogModuleEnum.Type.AUTHORITY_DIRECTION,content = "数据字典管理-删除字典值")
    @RequestMapping(value = "/delDirection/{id}")
    public KingHoodResponseVO<?> delDirectionById(@PathVariable Long id) {
        return systemDirectionService.delDirectionById(id);
    }


    /**
     * 根据ID查询详情
     *
     * @param id 身份证件
     * @author jp
     * @date 2024/01/03
     */
    @RequestMapping(value = "/queryDirectionById/{id}")
    public KingHoodResponseVO<?> queryDirectionById(@PathVariable("id") Long id) {
        return systemDirectionService.queryDirectionById(id);
    }

    /**
     * @description: 首页获取一些公共配置，如 华为文件目录
     * @date: 2019/8/9 10:25
     * @author: wangchao
     * @param:
     * @return:
     */
    @RequestMapping(value = "/queryConfig", method = RequestMethod.POST)
    public Object queryConfig(@RequestBody DirectionReqExtDTO data) {
        return KingHoodResponseVO.success(systemDirectionService.selectOptionList(data, false));
    }

    /**
     * 公共配置下拉(返回list)
     *
     * @param data
     * @return
     * @Description:
     * @Copyright 深圳金雅福控股集团有限公司
     * @author zhouzj
     * @Date 2021-9-2316:37:49
     * @Version: 1.0
     */
    @RequestMapping(value = "/queryConfigList", method = RequestMethod.POST)
    public Object queryConfigList(@RequestBody DirectionReqExtDTO data) {
        return KingHoodResponseVO.success(systemDirectionService.selectOptionList(data, true));
    }

    /**
     * @description: 机构根据code获取
     * @date: 2023/4/6 10:53
     * @Author: Tom
     * @param: [directionReqExtDTO]
     * @return: com.jinyafu.base.common.dto.KingHoodResponseVO<?>
     */
    @RequestMapping(value = "/optionList", method = RequestMethod.POST)
    public KingHoodResponseVO<?> optionList(@RequestBody @Valid DirectionReqExtDTO directionReqExtDTO) {
        return KingHoodResponseVO.success(systemDirectionService.selectOptionList(directionReqExtDTO, true));
    }

    /**
     * 根据code获取信息
     *
     * @param directionReqExtDTO 方向req ext dto
     * @author jp
     * @date 2024/01/08
     */
    @RequestMapping(value = "/getDirectionByCodeList", method = RequestMethod.POST)
    public List<DirectionRemoteVO> getDirectionByCodeList(@RequestBody @Valid DirectionReqRemoteDTO directionReqExtDTO) {
        return systemDirectionService.getDirectionByCodeList(directionReqExtDTO);
    }
}
